package com.moly.virgo.service;


import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;

@Service(value = "personService")
public class PersonService {

    @Autowired
    private RestHighLevelClient restHighLevelClient;

    public void test()  {

        System.out.println(22);
        System.out.println(restHighLevelClient);
        System.out.println(22);
        GetRequest getRequest = new GetRequest();
        getRequest.index("person").id("QST-pWsBTtIVnaXkdgTV");

        String[] includes = new String[]{"age", "*Date"};
        String[] excludes = Strings.EMPTY_ARRAY;
        FetchSourceContext fetchSourceContext =
                new FetchSourceContext(true, includes, excludes);
        getRequest.fetchSourceContext(fetchSourceContext);

        getRequest.storedFields("age");
        GetResponse documentFields = null;
        try {
            documentFields = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println(documentFields);
        System.out.println(documentFields);
        Map<String, DocumentField> fields = documentFields.getFields();
        System.out.println(fields);
    }

    public void test1(){

    }
}
